//
//  CVCellOfSpecialistCharts.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/13.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "CVCellOfSpecialistCharts.h"
#import "BaseButton.h"
#import "MJMacro.h"
#import "BaseCollectionView.h"
#import "CVCellOfInsideSpecialistCharts.h"
@interface CVCellOfSpecialistCharts()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UIView *blueView;
@property (nonatomic, strong) BaseCollectionView *collectionViewOfSpecialistCharts;
@property (nonatomic, strong) BaseButton *buttontitle;
@end
@implementation CVCellOfSpecialistCharts
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 创建上面的
        [self createAboveButton];
        // 创建下面的 collectView
        [self createCollectView];
    }
    return self;
}
#pragma mark - 创建子上面的 label
- (void)createAboveButton{
    // 热门推荐 button
    BaseButton *buttonOfHotRecommend = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfHotRecommend.frame = CGRectMake(0, 0, SCREEN_WIDTH / 4, 44);
    buttonOfHotRecommend.backgroundColor = [UIColor whiteColor];
    [buttonOfHotRecommend setTitle:@"热门推荐" forState:UIControlStateNormal];
    [buttonOfHotRecommend addTarget:self action:@selector(clickHotRecommendButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:buttonOfHotRecommend];
    // 最高评价 button
    BaseButton *buttonOfHighestEvaluation = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfHighestEvaluation.frame = CGRectMake(SCREEN_WIDTH / 4, 0, SCREEN_WIDTH / 4, 44);
    buttonOfHighestEvaluation.backgroundColor = [UIColor whiteColor];
    [buttonOfHighestEvaluation setTitle:@"最高评价" forState:UIControlStateNormal];
    [buttonOfHighestEvaluation addTarget:self action:@selector(clickHighestEvaluationButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:buttonOfHighestEvaluation];
    // 预约最多的 button
    BaseButton *buttonOfMostAppointment = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfMostAppointment.frame = CGRectMake(SCREEN_WIDTH / 4 * 2, 0, SCREEN_WIDTH / 4, 44);
    buttonOfMostAppointment.backgroundColor = [UIColor whiteColor];
    [buttonOfMostAppointment setTitle:@"预约最多" forState:UIControlStateNormal];
     [buttonOfMostAppointment addTarget:self action:@selector(clickMostAppointmentButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:buttonOfMostAppointment];
    // 最新加入 button
    BaseButton *buttonOfNewJoin = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfNewJoin.frame = CGRectMake(SCREEN_WIDTH / 4 * 3, 0, SCREEN_WIDTH / 4, 44);
    buttonOfNewJoin.backgroundColor = [UIColor whiteColor];
    [buttonOfNewJoin setTitle:@"最新加入" forState:UIControlStateNormal];
    [buttonOfNewJoin addTarget:self action:@selector(clickNewJoinButton:) forControlEvents:UIControlEventTouchUpInside];

    [self.contentView addSubview:buttonOfNewJoin];
    // 下面的蓝色的条
    self.blueView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 8 - 40, 42, 80, 2)];
    self.blueView.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:_blueView];
}
#pragma mark - 热门推荐 button 的点击方法
- (void)clickHotRecommendButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40, 42, 80, 2);
    _collectionViewOfSpecialistCharts.contentOffset = CGPointMake(0, 0);
}
#pragma mark - 最高评价 button 的点击方法
- (void)clickHighestEvaluationButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40 + SCREEN_WIDTH / 4, 42, 80, 2);
    _collectionViewOfSpecialistCharts.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
}
#pragma mark - 预约最多 button 的点击方法
- (void)clickMostAppointmentButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40 + SCREEN_WIDTH / 4 * 2, 42, 80, 2);
    _collectionViewOfSpecialistCharts.contentOffset = CGPointMake(SCREEN_WIDTH * 2, 0);
}
#pragma mark - 最新加入 button 的点击方法
- (void)clickNewJoinButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40 + SCREEN_WIDTH / 4 * 3, 42, 80, 2);
    _collectionViewOfSpecialistCharts.contentOffset = CGPointMake(SCREEN_WIDTH * 3, 0);
}
#pragma mark - 创建下面的 CollectView
- (void)createCollectView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 44);
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionViewOfSpecialistCharts = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0,44, SCREEN_WIDTH,SCREEN_HEIGHT - 64 - 44) collectionViewLayout:layout];
    self.collectionViewOfSpecialistCharts.pagingEnabled = YES;
    [self.contentView addSubview:_collectionViewOfSpecialistCharts];
    self.collectionViewOfSpecialistCharts.delegate = self;
    self.collectionViewOfSpecialistCharts.dataSource = self;
    [self.collectionViewOfSpecialistCharts registerClass:[CVCellOfInsideSpecialistCharts class] forCellWithReuseIdentifier:@"CVCellOfInsideSpecialistCharts"];
}
#pragma mark - collectionView 代理方法 item 数量的确定
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}
#pragma mark - collectionView 代理方法 cell 的赋值
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CVCellOfInsideSpecialistCharts *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CVCellOfInsideSpecialistCharts" forIndexPath:indexPath];
    cell.numberOfItem = indexPath.row;
    cell.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0f green:arc4random() % 256 / 255.0f blue:arc4random() % 256 / 255.0f alpha:1];
    return cell;
}
#pragma mark - scrollView  滑动连动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x == 0) {
        [self clickHotRecommendButton:nil];
    } else if (scrollView.contentOffset.x == SCREEN_WIDTH) {
        [self clickHighestEvaluationButton:nil];
    } else if (scrollView.contentOffset.x == SCREEN_WIDTH * 2) {
        [self clickMostAppointmentButton:nil];
    } else if (scrollView.contentOffset.x == SCREEN_WIDTH * 3){
        [self clickNewJoinButton:nil];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
